package c.h.a.k0.a;

import android.content.Context;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.RingtoneManager;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import c.h.a.m0.h;
import c.h.a.y.a;
import com.liuzh.deviceinfo.tests.TestesActivity;

/* compiled from: EarSpeakerTestFragment */
public class a0 extends a {
    public MediaPlayer W;
    public TestesActivity X;
    public View Y;
    public Integer Z = null;
    public Boolean b0 = null;
    public AudioManager c0;

    public void D(Context context) {
        super.D(context);
        TestesActivity testesActivity = (TestesActivity) context;
        this.X = testesActivity;
        testesActivity.setTitle(2131689815);
    }

    public void E(Bundle bundle) {
        super.E(bundle);
        AudioManager audioManager = (AudioManager) this.X.getSystemService("audio");
        this.c0 = audioManager;
        if (audioManager != null) {
            this.Z = Integer.valueOf(audioManager.getMode());
            this.b0 = Boolean.valueOf(this.c0.isSpeakerphoneOn());
            this.c0.setMode(3);
            this.c0.setSpeakerphoneOn(false);
            this.X.setVolumeControlStream(0);
            this.W = new MediaPlayer();
            try {
                this.W.setDataSource(this.X, RingtoneManager.getDefaultUri(1));
                this.W.prepare();
            } catch (Exception unused) {
            }
        }
    }

    public View G(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        if (this.Y == null) {
            View inflate = layoutInflater.inflate(2131493072, viewGroup, false);
            this.Y = inflate;
            ImageView imageView = (ImageView) inflate.findViewById(2131296633);
            if (s().getConfiguration().orientation == 2) {
                imageView.setTranslationY((float) (-h.t(35.0f, s().getDisplayMetrics())));
            }
            imageView.setImageResource(2131231119);
            ((TextView) this.Y.findViewById(2131296715)).setText(2131689816);
            this.Y.findViewById(2131296650).setOnClickListener(new h(this));
            this.Y.findViewById(2131296653).setOnClickListener(new g(this));
        }
        return this.Y;
    }

    public void H() {
        MediaPlayer mediaPlayer = this.W;
        if (mediaPlayer != null) {
            mediaPlayer.stop();
            this.W.release();
            this.W = null;
        }
        AudioManager audioManager = this.c0;
        if (audioManager != null) {
            Boolean bool = this.b0;
            if (bool != null) {
                audioManager.setSpeakerphoneOn(bool.booleanValue());
            }
            Integer num = this.Z;
            if (num != null) {
                this.c0.setMode(num.intValue());
            }
        }
        this.E = true;
    }

    public void N() {
        MediaPlayer mediaPlayer = this.W;
        if (mediaPlayer != null) {
            try {
                mediaPlayer.pause();
            } catch (Exception unused) {
            }
        }
        this.E = true;
    }

    public void P() {
        this.E = true;
        MediaPlayer mediaPlayer = this.W;
        if (mediaPlayer != null) {
            try {
                mediaPlayer.start();
            } catch (Exception unused) {
            }
        }
    }
}
